<?php

/*载入每个页面的controller模块*/
function LoadDataModule( $page_base ) {
    if (file_exists(DIR_MODULE.$page_base.'/header_php.php')) {
        return DIR_MODULE.$page_base.'/header_php.php';
    }
    else
    	return DIR_MODULE.'common/header_php.php';
}

/*
*载入页面布局，重载机制。
*如果存在tpl/[page_base]/layout.php，就用该布局。
*否则使用tpl/common/layout.php 
*/
function LoadPageLayout( $page_base ) {
    if (file_exists(DIR_TPL.$page_base.'/layout.php')) {
        return DIR_TPL.$page_base.'/layout.php';
    }else {
        return DIR_TPL.'common/layout.php';
    }
}

/*
*载入页面html header，重载机制。
*如果存在tpl/[page_base]/html_header.php，就用该文件。
*否则使用tpl/common/html_header.php 
*/
function LoadHtmlHeader( $page_base ) {
    if (file_exists(DIR_TPL.$page_base.'/html_header.php')) {
        return DIR_TPL.$page_base.'/html_header.php';
    }else {
        return DIR_TPL.'common/html_header.php';
    }
}

/*
*载入页面头部，重载机制。
*如果存在tpl/[page_base]/page_header.php，就用该文件。
*否则使用tpl/common/page_header.php 
*/
function LoadPageHeader( $page_base,$is_backend=false ) {
	
	eval( EdpExportGlobalVars() );
	
    if (file_exists(DIR_TPL.$page_base.'/page_header.php')) {
        require_once( DIR_TPL.$page_base.'/page_header.php' );
    }else {
   
		if(!$is_backend){
			require_once( DIR_MODULE.'common/header_php.php' );
			require_once( DIR_TPL.'common/page_header.php' );		
		}	
        else{
        	require_once( DIR_MODULE.'common/header_php_backend.php' );
           	require_once( DIR_TPL.'common/page_header_backend.php' );     	
        }
    }
}

/*
*载入页面主体，每个页面主体不一样，不需要重载。
*如果存在tpl/[page_base]/page_body.php，就用该文件。
*否则跳转到page not found
*/
function LoadPagebody( $page_base ) 
{
	global $transfer;
	
	if( !is_null($transfer) )
		return DIR_TPL . $page_base . '/' . $transfer . '.php';
		
    else if( file_exists( DIR_TPL . $page_base . '/page_body.php' ) ) 
        return DIR_TPL . $page_base.'/page_body.php';
    else
    	return DIR_TPL . PAGE_NOT_FOUND . '/page_body.php';
}

function LoadTinyPageBody( $page_base )
{
 	if( file_exists(DIR_TPL.$page_base.'/page_body.php') ) 
 		return DIR_TPL . $page_base . '/page_body.php' ;
 		
	return "";
}

/*
*载入页面尾部，重载机制。
*如果存在tpl/[page_base]/page_footer.php，就用该文件。
*否则使用tpl/common/page_footer.php 
*/
function LoadPageFooter( $page_base ) {
    if (file_exists(DIR_TPL.$page_base.'/page_footer.php')) {
        return DIR_TPL.$page_base.'/page_footer.php';
    }else {
        return DIR_TPL.'common/page_footer.php';
    }
}


/*
*载入主体部分的子模块和子页面，重载机制。
*子模块和子页面的先后载入和对应关系，做到了数据和页面分离。
*如果存在module/[page_base]/[sub_page].php，就用该文件。
*否则使用module/common/[sub_page].php 
*如果存在tpl/[page_base]/tpl_[sub_page].php，就用该文件。
*否则使用tpl/common/tpl_[sub_page].php 
*/

function LoadSubpage( $page_base, $subpage ) {
			
    if (file_exists(DIR_MODULE.$page_base.'/'.$subpage.'.php')) {
        require_once(DIR_MODULE.$page_base.'/'.$subpage.'.php');
    }
    else if (file_exists(DIR_MODULE.'common/'.$subpage.'.php')) {
        require_once(DIR_MODULE.'common/'.$subpage.'.php');
    }

    if (file_exists(DIR_TPL.$page_base.'/tpl_'.$subpage.'.php')) {
        require_once(DIR_TPL.$page_base.'/tpl_'.$subpage.'.php');
    }
    else if (file_exists(DIR_TPL.'common/tpl_'.$subpage.'.php')) {
        require_once(DIR_TPL.'common/tpl_'.$subpage.'.php');
    }
}

/**********************************************************
 *	This function enables a page to load a dependent page, 
 *	including the module and body.	This is different
 *	from the LoadSubpage because the loaded page is not
 *	a subpage of the loading page, instead it may be reused
 *	among many pages.
 *
 *	Seal Created by 2009-12-14
 **********************************************************/
function LoadDependentPage( $page_base )
{
	// For RCP, should be considered here
	global $RCPSMatrix;
	if( in_array($page_base, $RCPSMatrix) )
		edp_setsession( $page_base, '0' );
	
 	if( file_exists( DIR_MODULE . "$page_base/header_php.php" ) ) 
        require_once( DIR_MODULE . "$page_base/header_php.php" );
    
    if( file_exists( DIR_TPL . "$page_base/page_body.php" ) ) 
        require_once( DIR_TPL . "$page_base/page_body.php" );
}


/**********************************************************
 *	Clear the input to the database for security
 *	Seal Created by 2009-10-13
 **********************************************************/
function edp_db_input( $string )
{
	//mysql_escape_string has been DEPRECATED as of PHP 5.3.0
	//and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged.
	
	GetDB();

    if(is_string( $string )){
        if(get_magic_quotes_gpc())
        {
            $string =  mysql_real_escape_string( stripslashes($string) );
        }
        else
        {
            $string = mysql_real_escape_string( $string );
        }
    }
	
	/*
	// prevent from xss attack by using the script in the content
	$string = preg_replace( '/&/', "" , $string );
	$string = preg_replace( '/</', "\&lt;" , $string );
	$string = preg_replace( '/\\\\/', "" , $string );
	*/
	// prevent using the comment notation in MySQL
	// double '-' makes a sql comment
	//$string = str_replace( '\r\n', "\r\n", $string );
	
	return $string;
	
	
}

/**********************************************************
 *	Clear the date to be displayed in the web page
 *	Seal Created by 2009-10-13
 **********************************************************/
function edp_db_output( $string ) 
{
	return htmlspecialchars( $string );
}

/**
 * Redirect to another page or site
 * @param string The url to redirect to
*/
function edp_redirect($url) {
	
// modified by jszhang, use javascript to redirect
//  // clean up URL before executing it
//    while (strstr($url, '&&')) $url = str_replace('&&', '&', $url);
//    while (strstr($url, '&amp;&amp;')) $url = str_replace('&amp;&amp;', '&amp;', $url);
//    // header locates should not have the &amp; in the address it breaks things
//    while (strstr($url, '&amp;')) $url = str_replace('&amp;', '&', $url);
//
//    header('Location: ' . $url);
	echo "<script type=\"text/javascript\">window.location = \"$url\";</script>";

    edp_exit();
  }

/**********************************************************
 *
 *  Save session and get session function.
 *  Pay attention, do not use the $_SESSION directly to save
 *  or read data in the session. Because we may reimplement
 *  the session mechanism ourself. Very important!
 * 
 *	Seal Created by 2009-10-16
 **********************************************************/
function edp_setsession( $name, $value)
{
	$_SESSION[ "$name" ] = $value;
}

function edp_getsession( $name )
{
	return $_SESSION[ "$name" ];
}

function edp_isset_session( $name )
{
	return isset( $_SESSION["$name"] );
}

function edp_unset_session( $name )
{
	unset($_SESSION["$name"]);
}

function edp_is_empty_string( $string )
{
	if( is_array($string) )
	{
		if( count($string) == 0 )
			return true;
		else
			return false;
	}
	if( !isset( $string ) ||  is_null($string) || strlen( trim($string) ) == 0 )
		return true;
	return false;
}

/* Generate URL*/
function edp_href_link($page = '', $parameters = '') 
{
	global $backendPage, $frontendPage;
    if ($page == '') {
      die('error');
    }
    
    if ($page == 'index') {
      return EDP_DOMAIN;;
    }   
    
    $link = EDP_DOMAIN;
    
    if( trim($parameters) == '' )
    	return $link . $page;
    
    if( in_array($page, $frontendPage) ){
    	
	    preg_match( '/(sid|pid|lid|rid|platid)=(\d+)&?/', $parameters, $matches );
	    if( count($matches) > 0 ){
	    	$link = $link . "$page/" . $matches[2];
	    	$parameters = preg_replace( '/(sid|pid|lid|rid|platid)=(\d+)&?/', '', $parameters );
	    }
	    
    } elseif ( in_array($page, $backendPage) ) {
    	
   		preg_match( '/(uid)=(\d+)&?/', $parameters, $matches );
	    if( count($matches) > 0 ){
	    	$link = $link . "$page/" . $matches[2];
	    	$parameters = preg_replace( '/(uid)=(\d+)&?/', '', $parameters );
	    }
	    else{
		$link = $link . "$page/";
	    } 
    } else {
    	$link = $link . "$page/";
    }
    
       
    if( !empty($parameters) ){
    	$link .= '?';
    	$link = $link . $parameters;
    }

    return $link;
}


/**
 * echo page var on html
 * @param array $pageVars
 * @param string $key
 */
function echoPageVar( $pageVars, $key, $ishtml=false ){
	if($ishtml==true)
	{
		secho( isset($pageVars) && isset($pageVars[$key]) ?  preg_replace( "/rn/", "\n", $pageVars[$key]) : '' );
	}
	else
	{
		echo( isset($pageVars) && isset($pageVars[$key]) ?  preg_replace( "/rn/", "\n", $pageVars[$key]) : '' );
	}
}



/**********************************************************
 *	Sometimes in the module header, we want to go to 
 * 	different pages according to different situations, this
 *  function just goes to the assigned page in the same
 *  directory of the page_body.php file.
 *	Seal Created by 2009-10-27
 **********************************************************/
function TransferTo( $pagename )
{
	global $transfer;
	$transfer = $pagename;
}



function getUserRealIPAddr()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
    {
      $ip=$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
    {
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
      $ip=$_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}

/**
 * swap array key and value
 * @param array $array
 * @return array
 */
function SwapArray($array){
    $result = array();
    while(list($key,$val) = each($result))
        $result[$val] = $key;
    return $result;
}

/*
* get score class number
* use as this <span class="score<? echo getScoreClass($score); ?>"/>
*/
function getScoreClass($score){

	$score= intval($score);
	switch(floor($score/10)){

		case 0:{

		   if($score==0)
		    return '0';
		   else if($score<2.5)	
			return '05';
		   else if($score>2.5&$score<5)
		    return '1';
		   else if($score>=5&$score<7.5) 
 		    return '15';
		   else return '2';
			
		   break;
		}
		case 1:{
			
		   if($score<12.5)	
			return '2';
		   else if($score>12.5&$score<17.5)
		    return '25';
		   else return '3';

		   break;				
		}
		case 2:{
			
		   if($score<22.5)	
			return '3';
		   else if($score>22.5&$score<27.5)
		    return '35';
		   else return '4';

		   break;									
		}
		case 3:{
													
		   if($score<32.5)	
			return '4';
		   else if($score>32.5&$score<37.5)
		    return '45';
		   else return '5';

		   break;				
		}
		case 4:{					
			return '5';
		}				
	}
}

/*
* get user rank number
* use as this <span class="<? echo getUserRankClass($contribution); ?>"/>
*/

function getUserRankClass($contribution){

	$contribution= intval($contribution);
	if($contribution>=0&$contribution<=50)
	  return 'star1';
	if($contribution>=51&$contribution<=100)
	  return 'star2';
	if($contribution>=101&$contribution<=200)
	  return 'star3';
	if($contribution>=201&$contribution<=400)
	  return 'star4';
	if($contribution>=401&$contribution<=750)
	  return 'moon1';	
	if($contribution>=751&$contribution<=1300)
	  return 'moon2';	
	if($contribution>=1301&$contribution<=2100)
	  return 'moon3';	
	if($contribution>=2101&$contribution<=3200)
	  return 'moon4';
	if($contribution>=3201&$contribution<=4650)
	  return 'sun1';	
	if($contribution>=4651&$contribution<=6500)
	  return 'sun2';	
	if($contribution>=6501&$contribution<=8800)
	  return 'sun3';	
	if($contribution>=8801)
	  return 'sun4';	 
}	 	 

function edp_exit() 
{
   
   session_write_close();
   exit();
}

function GetCurrentDate( $format = 'Y-n-j H:i:s' )
{
	date_default_timezone_set('Asia/Shanghai');
	return date( $format );
}

// return the physical path for the picture
function EdpGetPicPath( $shortPath )
{
	return DIR_UPLOAD_FILE . $shortPath;
}

function EdpGetSmallPicPath( $shortPath )
{
	return EdpGetPicPath( EdpGetSmallPicName($shortPath) );
}






// return the URL for the picture
function EdpGetPicURL( $shortPath )
{
	return UPLOAD_PIC_DIR . $shortPath;
}

function EdpGetSmallPicURL( $shortPath, $logical = true )
{
	return EdpGetPicURL( EdpGetSmallPicName( $shortPath ) );
}

function EdpGetSmallPicName( $normalName )
{
	return preg_replace( '/.jpg$/', "s.jpg", $normalName );
}

// return URL for the header picture
function EdpGetAvatarUrl( $shortPath )
{
	if( edp_is_empty_string($shortPath) )
		return DEFAULT_AVATAR_URL;
		
	return UPLOAD_AVATAR_DIR . $shortPath;
}

//	return URL for the coupon picture
function EdpGetCouponPicUrl( $shortPath )
{
	if( edp_is_empty_string($shortPath) )
		return DEFAULT_COUPON_URL;
		
	return UPLOAD_COUPON_DIR . $shortPath;
}

// return URL for the original header picture
function EdpGetOriAvatarUrl( $headerPic )
{
	if( edp_is_empty_string($headerPic) )
		return DEFAULT_AVATAR_URL;
		
	return UPLOAD_AVATAR_DIR . preg_replace( '/s.jpg$/', ".jpg", $headerPic );;
}

function EdpGetAvatarPath( $shortPath )
{
	return DIR_AVATAR . $shortPath;
}


function SetEmptyIfUndefined( $variable )
{
	if( isset($_POST["$variable"]) )
		if( is_array($_POST["$variable"]) )
			return $_POST["$variable"];
		else
			return trim($_POST["$variable"]);
	else
		return "";
}

function PrintIfSet( $variable, $index )
{
	global ${$variable};
	if( isset(${$variable}) )
	{
		if( is_array(${$variable}) )
			secho( ${$variable}[$index] );
		else
			secho( ${$variable} );
	}
	else
		echo "";
}

function& FindItemByValue( &$array_input, $key, $value )
{
	foreach( $array_input as $k => $v)
	{
		if( $v[$key] == $value)
			return $array_input[$k];
	}
	
	return null;
}

function edp_redirect_inner( $pagebase, $getParams )
{
	
	header( "Location: " . edp_href_link($pagebase, $getParams) );
	exit();
}

function edp_redirect_inner_uri( $uri )
{
	
	header( "Location: " . $uri );
}

function IsParaOK()
{
	global $page_validate, $page_base;
	
	$errmsg = GetMessageStack();
	
	if( $page_validate == VALIDATION_OK && 
		$errmsg->size("EVF") == 0 )
	{
		return true;
	}
	
	return false;
}

function GET( $para )
{
	if( !isset($_GET["$para"]) )
		return null;
		
	return trim( $_GET["$para"] );
	
}

function POST( $para )
{
	if( !isset($_POST["$para"]) )
		return null;
		
	return trim( $_POST["$para"] );	
}

function echo_validation_message()
{
	$className = "EVF";
	$numargs = func_num_args();
	if( $numargs == 1 )
		$className = func_get_arg(0);
		
	$message = GetMessageStack();
	$message->outputPlain( $className );
}

function get_validation_message( $module = null )
{
	
	$message = GetMessageStack();
	if( $module == null )
		return $message->getPlain( "EVF" );
	
	return $message->getPlain( $module );
}

function secho( $strContent )
{
	echo sconv($strContent);
}

function sconv( $strContent )
{
    if(is_array( $strContent ) ){
        foreach( $strContent as $item ){
            return sconv($item);
        }
    }
    else if(is_string( $strContent )){
        return htmlentities($strContent, ENT_QUOTES, "UTF-8"); 
    }
    else{
        return $strContent;
    }
}

/**
 * gbk to utf encoding convert
 * 
 * @param type $str
 * @return type 
 */
function GBKtoUTF8($str)
{
    if(is_array($str))
    {
        foreach ($str as &$value) 
        {
            $value = GBKtoUTF8($value);
        }
        return $str;
    }
    elseif (is_string($str))
    {   
        $str = iconv("GBK", "UTF-8//IGNORE", $str);
        return $str;
    }
    else
    {
        return $str;
    }
}

function newLineToBr( $content )
{
	$order   = array("\r\n", "\n", "\r");
	$replace = '<br />';
	return str_replace($order, $replace, $content);
}

// Let the RCP system to clear the flag to allow the user second commit
// when one commit fails
function edp_allow_next_commit(){
	
	global $allowNextCommit;
	
	$allowNextCommit = 1;
	
}

function EdpFilterHtmlTag( $ori )
{
	$farr = array(
		"/\s /", 
		"/<(\/?)(script|i?frame|style|html|body|title|link|meta|\?|\%)([^>]*?)>/isU", 
		"/(<[^>]*)on[a-zA-Z] \s*=([^>]*>)/isU"
	);
	
	$tarr = array(
		" ",
		"", 
		""
	);

	$count = 0;
	do{
		$ori = preg_replace( $farr,$tarr,$ori, -1, $count );
	}while( $count > 0 );
	
	
	return $ori; 
}

function EdpExportGlobalVars(){
	
	$excludeVars = array(
		"GLOBALS", "_POST", "_GET", "_COOKIE", "_FILES"
	);
	
	$exeStat = "global "; 
	$globalVars = '';
	foreach ( $GLOBALS as $varName => $varValue )
		if( array_search( $varName, $excludeVars ) === false )
			$globalVars .= '$' . $varName . ',';

	if( $globalVars != '' )
		$exeStat .= rtrim( $globalVars, "," ) . ';';
	else
		$exeStat .= ' GLOBALS;'; 
		
	return $exeStat;
}

function EdpGetProfessional( $iNum ){
	static $professionMap = array(
	 "0" => " 保密 ",  "1" => " 高科技 ",	 "2" => " 空间科技 ",	 "3" => " 计算机硬件 ",	 "4" => " 计算机软件 ",
	 "5" => " 计算机网络设备 ",	 "6" => " 计算机&网络安全 ",	 "7" => " 计算机游戏 ",	 "8" => " 互联网 ",
	 "9" => " 半导体 ",	 "10" => " 电信&通讯 ",	 "11" => " 纳米技术 ",	 "12" => " 信息技术与服务 ",	 "13" => " 无线通讯 ",
	 "14" => " 法律 ",	 "15" => " 法律援助 ",	 "16" => " 法律服务 ",	 "17" => " 专业咨询、服务 ",	 "18" => " 管理咨询 ",
	 "19" => " 招聘、猎头 ",	 "20" => " 人力资源 ",	 "21" => " 培训 ",	 "22" => " 市场推广&广告 ",	 "23" => " 市场调研 ",
	 "24" => " 公共关系 ",	 "25" => " 翻译服务 ",	 "26" => " 设备维护 ",	 "27" => " 外包服务 ",	 "28" => " 会务及活动服务 ",
	 "29" => " 医疗与健康 ",	 "30" => " 生物工程 ",	 "31" => " 生物信息 ",	 "32" => " 医院&医疗 ",	 "33" => " 医药品 ",
	 "34" => " 医疗设备 ",	 "35" => " 兽医 ",	 "36" => " 健身 ",	 "37" => " 心理健康 ",	 "38" => " 中医 ",
	 "39" => " 媒体 ",	 "40" => " 广播 ",	 "41" => " 电视 ",	 "42" => " 电影 ",	 "43" => " 报纸 ",	 "44" => " 杂志 ",
	 "45" => " 出版 ",	 "46" => " 写作&编辑 ",	 "47" => " 文化艺术 ",	 "48" => " 印刷 ",	 "49" => " 互联网媒体 ",	 "50" => " 媒体设计制作 ",
	 "51" => " 体育、休闲、旅游、娱乐 ",	 "52" => " 娱乐业 ",	 "53" => " 休闲度假&旅游 ",	 "54" => " 餐饮业 ",	 "55" => " 住宿业 ",
	 "56" => " 体育运动 ",	 "57" => " 食品&饮料 ",	 "58" => " 娱乐设备与服务 ",	 "59" => " 金融 ",	 "60" => " 保险 ",
	 "61" => " 财经服务 ",	 "62" => " 房地产 ",	 "63" => " 投资银行 ",	 "64" => " 风险投资 ",	 "65" => " 私募股权投资 ",
	 "66" => " 证券 ",	 "67" => " 会计 ",	 "68" => " 非盈利性组织 ",	 "69" => " 非盈利性组织管理 ",	 "70" => " 公益基金 ",
	 "71" => " 智囊团 ",	 "72" => " 慈善事业 ",	 "153" => " 科学研究 ",	 "73" => " 教育 ",	 "75" => " 高等教育 ",	 "76" => " 教育管理 ",
	 "77" => " E-Learning ",	 "78" => " 教育研究 ",	 "155" => " 幼儿园教师 ",	 "156" => " 小学教师 ",	 "157" => " 中学教师 ",
	 "79" => " 日常消费品 ",	 "80" => " 化妆品 ",	 "81" => " 服装服饰 ",	 "82" => " 体育用品 ",	 "83" => " 烟草 ",	 "84" => " 超市卖场 ",
	 "85" => " 食物生产 ",	 "86" => " 酒类 ",	 "87" => " 消费电子 ",	 "88" => " 快速消费品 ",	 "89" => " 家具 ",	 "90" => " 零售 ",
	 "91" => " 批发 ",	 "92" => " 进出口 ",	 "93" => " 奢侈品&珠宝 ",	 "94" => " 建筑 ",	 "95" => " 建筑工程 ",	 "96" => " 建材 ",
	 "97" => " 建筑设计 ",	 "98" => " 土木工程 ",	 "99" => " 装饰装潢 ",	 "100" => " 制造 ",	 "101" => " 工艺品 ",	 "102" => " 飞行航空&宇航 ",	 
	 "103" => " 汽车 ",	 "104" => " 化工 ",	 "105" => " 电子电气设备 ",	 "106" => " 机械 ",	 "107" => " 采矿&金属 ",	 "108" => " 石油&能源 ",
	 "109" => " 回收&环境保护 ",	 "110" => " 造船 ",	 "111" => " 纺织及皮革制造 ",	 "112" => " 造纸&木材 ",	 "113" => " 铁路 ",
	 "114" => " 玻璃, 陶瓷&混凝土 ",	 "115" => " 包装&集装箱 ",	 "116" => " 工业管理 ",	 "117" => " 工业自动化 ",	 "122" => " 政府及公共事业 ",
	 "123" => " 军事机构 ",	 "124" => " 司法机关 ",	 "125" => " 外交 ",	 "126" => " 行政部门 ",	 "127" => " 卫生社会福利 ",	 "128" => " 水利环境公共设施 ",
	 "129" => " 地质勘探 ",	 "130" => " 水电燃气生产供应 ",	 "131" => " 公共安全 ",	 "154" => " 社会保障 ",	 "132" => " 公共服务业 ",
	 "133" => " 信息服务 ",	 "134" => " 图书馆及博物馆 ",	 "135" => " 保安服务 ",	 "136" => " 环保服务 ",	 "137" => " 家政服务 ",
	 "138" => " 宗教协会 ",	 "139" => " 交通运输 ",	 "140" => " 邮政，包裹，零担货运 ",	 "141" => " 物流与供应链 ",	 "142" => " 运输/汽运/铁路 ",
	 "143" => " 仓储 ",	 "144" => " 航空运输 ",	 "145" => " 水上运输 ",	 "146" => " 客运及城市公共交通 ",	 "147" => " 农林牧渔业 ",
	 "121" => " 渔业 ",	 "120" => " 林业 ",	 "118" => " 畜牧 ",	 "148" => " 商品贸易 ",	 "149" => " 国内贸易 ",	 "150" => " 国际贸易 ",
	 "151" => " 其他行业 ",	 "152" => " 其他行业 ");
	
	return $professionMap[$iNum];
}

function EdpGetEducationLevel( $iNum ){
	static $educationLevelMap = array(
		 "0" => "保密",
		 "1" => "专科",
		 "2" => "本科",
		 "3" => "硕士",
		 "4" => "博士",
		 "5" => "其他"
	);
	
	return $educationLevelMap[$iNum];
}

function EdpGetRevenue( $iNum ){
	static $revenueMap = array(
		 "0" => "保密",
		 "1" => "5000以下",
		 "2" => "5000-10000",
		 "3" => "10000-20000",
		 "4" => "20000以上"
	);
	
	return $revenueMap[$iNum];
}

$shopCategoryMapping=array("服饰"=>array('12'=>"男装", '13'=>"运动鞋", '16'=>"女装/流行女装", '17'=>"女鞋", '18'=>"女士内衣/男士内衣/家居服", '21'=>"箱包皮具/热销女包/男包", '25'=>"流行男鞋/皮鞋", '50'=>"童装/婴儿服/鞋帽", '51'=>"运动服", '52'=>"服饰配件/皮带/帽子/围巾"),
						   "手机/数码/办公/家电"=>array('1'=>"手机", '2'=>"笔记本电脑", '3'=>"电脑硬件/台式机/网络设备", '5'=>"MP3/MP4/iPod/录音笔", '6'=>"数码相机/摄像机/图形冲印", '7'=>"3C数码配件市场", '8'=>"家用电器/hifi音响/耳机", '9'=>"网络服务/电脑软件", '11'=>"闪存卡/U盘/移动存储", '33'=>"办公设备/文具/耗材"),
						   "家具/母婴/食品"=>array('29'=>"居家日用/厨房餐饮/卫浴洗浴", '30'=>"时尚家饰/工艺品/十字绣", '31'=>"家具/家具定制/宜家代购", '32'=>"床上用品/靠垫/窗帘/布艺", '35'=>"装潢/灯具/五金/安防/卫浴", '36'=>"保健品/滋补品", '37'=>"食品/茶叶/零食/特产", '38'=>"母婴用品/奶粉/孕妇装", '45'=>"宠物/宠物食品及用品", '46'=>"成人用品/避孕用品/情趣内衣"),
						   "美容护肤/个人护理"=>array('14'=>"个人护理/保健/按摩器材", '19'=>"彩妆/香水/护肤/美体"),
                           "运动/汽车"=>array('24'=>"运动/瑜伽/健身/球迷用品", '26'=>"户外/军品/旅游/机票", '28'=>"汽车/配件/改装/摩托/自行车", '42'=>"书籍/杂志/报纸", '43'=>"音乐/影视/明星/乐器"),
                           "珠宝/首饰"=>array('20'=>"珠宝/钻石/翡翠/黄金", '22'=>"品牌手表/流行手表", '23'=>"饰品/流行首饰/时尚饰品"),
						   "收藏/爱好"=>array('27'=>"ZIPPO/瑞士军刀/饰品/眼镜", '40'=>"玩具/动漫/模型/卡通", '44'=>"古董/邮币/字画/收藏"),
						   "游戏/话费"=>array('4'=>"IP卡/网络电话/在线影音充值", '10'=>"移动联通充值中心/IP长途", '15'=>"腾讯QQ专区", '34'=>"网络游戏装备/游戏币/帐号/代练", '39'=>"电玩/配件/游戏/攻略", '41'=>"网络游戏点卡"),
						   "生活服务"=>array('47'=>"网店装修/物流快递/图片存储", '48'=>"演出/旅游/吃喝玩乐折扣券", '49'=>"鲜花速递/蛋糕配送/园艺花艺"));

//根据页面的大类获取隐射类ID
function EdpGetSubShopCateByName($cateName)
{
	global $shopCategoryMapping;
	if(isset($shopCategoryMapping[$cateName]))
		return $shopCategoryMapping[$cateName];
	else
		return false;
}

//获取所有店铺分类映射
function EdpGetAllShopCateMapping()
{
	global $shopCategoryMapping;
	return $shopCategoryMapping;
}

/***
*商品静态已经过期，需要更新
*目前没有用到php的代码，等以后做商品分类页时候会用到
*add by Bo
/*
$productCategoryMapping=array("虚拟"=>array('18'=>"腾讯QQ专区", '26'=>"网游装备/游戏币/帐号/代练", '27'=>"IP卡/网络电话/手机号码", '28'=>"网络游戏点卡", '34'=>"移动/联通/小灵通充值中心"),
							  "数码"=>array('2'=>"数码相机/摄像机/摄影器材", '2'=>"3C数码配件市场", '3'=>"闪存卡/U盘/移动存储", '4'=>"办公设备/文具/耗材", '13'=>"MP3/MP4/iPod/录音笔", '14'=>"手机", '15'=>"国货精品手机", '17'=>"个人护理/保健/按摩器材", '19'=>"电脑硬件/台式整机/网络设备", '20'=>"笔记本电脑", '2'=>"电玩/配件/游戏/攻略", '54'=>"影音电器", '57'=>"厨房电器", '58'=>"生活电器"),
							  "美容"=>array('38'=>"彩妆/香水/美发/工具", '55'=>"美容护肤/美体/精油"),
							  "服装"=>array('22'=>"运动服/运动包/颈环配件", '23'=>"运动鞋", '40'=>"流行男鞋", '41'=>"女装/女士精品", '43'=>"女鞋", '44'=>"男装", '45'=>"女士内衣/男士内衣/家居服", '46'=>"服饰配件/皮带/帽子/围巾", '56'=>"箱包皮具/热销女包/男包"),
							  "配饰"=>array('37'=>"品牌手表/流行手表", '39'=>"饰品/流行首饰/时尚饰品", '47'=>"珠宝/钻石/翡翠/黄金", '48'=>"ZIPPO/瑞士军刀/眼镜"),
							  "家居"=>array('5'=>"居家日用/厨房餐饮/卫浴洗浴", '6'=>"家纺/床品/地毯/布艺", '7'=>"时尚家饰/工艺品/十字绣", '30'=>"家具/家具定制/宜家代购", '35'=>"装潢/灯具/五金/安防/卫浴", '51'=>"成人用品/避孕用品/情趣内衣"),
							  "母婴"=>array('8'=>"奶粉/尿片/母婴用品", '9'=>"益智玩具/童车/童床/书包", '10'=>"童装/童鞋/孕妇装"),
							  "食品"=>array('11'=>"食品/茶叶/零食/特产", '12'=>"保健食品"),
							  "文体"=>array('21'=>"运动/瑜伽/健身/球迷用品", '25'=>"玩具/模型/娃娃/人偶", '29'=>"古董/邮币/字画/收藏", '32'=>"户外/登山/野营/涉水", '33'=>"汽车/配件/改装/摩托/自行车", '42'=>"音乐/影视/明星/乐器", '49'=>"书籍/杂志/报纸", '50'=>"宠物/宠物食品及用品", '59'=>"演出/旅游/吃喝玩乐折扣券"),
							  "服务"=>array('1'=>'特价机票/门票旅游/酒店客栈','16'=>"网络服务/电脑软件", '31'=>"鲜花速递/蛋糕配送/园艺花艺", '36'=>"网店装修/物流快递/图片存储"),
							  "其他"=>array('52'=>"其它"));
*/
$hotTag=array("手机", "山寨", "高仿", "原单", "正品", "日本进口", "美国原装", "免费送货");

function EdpGetHotTag()
{
	global $hotTag;
	return $hotTag;
}

//根据页面的大类获取隐射类ID
function EdpGetSubProductCateByName($cateName)
{
	global $productCategoryMapping;
	if(isset($productCategoryMapping[$cateName]))
		return $productCategoryMapping[$cateName];
	else
		return false;
}

//获取所有店铺分类映射
function EdpGetAllProductCateMapping()
{
	global $productCategoryMapping;
	return $productCategoryMapping;
}

function EdpSubStr( $str, $start, $length, $encoding = 'utf-8')
{
	return mb_substr( $str, $start, $length, $encoding );
}

function EdpStrLen( $str, $encoding = 'utf-8' )
{
	return mb_strlen( $str, $encoding );
}

/**********************************************************
 *  convert PHP UNIX time format to MYSQL time format
 *	Seal Created by 2010-8-14
 **********************************************************/
function EdpUnixTimeStampToMySQL($timestamp)
{
	date_default_timezone_set('Asia/Shanghai');
    return date('Y-m-d H:i:s', $timestamp);
}

function EdpFilterSensitiveWords( $content )
{
	$cacheManager = GetCacheManager();
	
	$words = $cacheManager->Get( 'SensWords', CNS_SENS_WORD );
	
	if( $words == null ){
		$words = file_get_contents( 'fw.txt' );
		$cacheManager->Set( 'SensWords', $words, CNS_SENS_WORD );
	}
	
	$wordArray = mb_split( "\|", $words );
	foreach( $wordArray as $key => $value )
	{
		if( strstr($content, $value ) !== false)
			return false;
	}
	
	return true;
}

//字符串转大写函数
function EdpToUpper($str) 
{
	$len = strlen($str);
	for ($i=0;$i<$len;$i++) 
	{
		if(ord($str{$i}) >= 97 && ord($str{$i}) <= 122) 
		{
    		$str{$i} = chr(ord($str{$i})-32);
   		}
	}
	return $str;
}

//字符串转小写函数
function EdpToLower($str) 
{
	$len = strlen($str);
	for ($i=0;$i<$len;$i++) 
	{
   		if(ord($str{$i}) >= 65 && ord($str{$i}) <= 90) 
   		{
    		$str{$i} = chr(ord($str{$i})+32);
   		}
	}
	return $str;
}

function EdpGetGiftCouponPicURL( $shortPath )
{
	return GIFT_COUPON_PIC_URL . $shortPath;
}

function EdpCheckVcode( $vcode )
{
    if( $vcode != edp_getsession('vcode') )
        return false;

    return true;
}

$secKey = 'ffb6991624af0df4fb8edfefc2b0b4c2';

function EdpGetActivationCode( $userid, $username ){
    global $secKey;
    $tmp = md5("$userid;$secKey");
    $code = base64_encode( $tmp );

    return $code;
}

function IsActivationCodeValid( $userid, $username, $code ){
    global $secKey;
    $tmp = md5("$userid;$secKey");

    if( $tmp == base64_decode( $code ) )
    {
        return true;
    }
    else{
        return false;
    }
}
?>
